package cn.wolfcode.trip.app.controller;


import cn.wolfcode.trip.app.utils.UploadUtil;
import cn.wolfcode.trip.app.utils.UserContext;
import cn.wolfcode.trip.base.domain.Sign;
import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.service.ISignService;
import cn.wolfcode.trip.base.service.IUserService;
import cn.wolfcode.trip.base.utils.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletContext;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/sign")
public class SignController {
    @Autowired
    private ISignService signService;


    @PostMapping("/time")
    @ResponseBody
    public Object save(Sign sign){
        JSONResult result = new JSONResult();
        try {
            sign.setState(1);
            sign.setSignTime(new Date());
            sign.setUser(UserContext.getCurrentUser());
            sign.setCount(1);
            signService.sign(sign);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }

        return result;
    }


    @GetMapping
    @ResponseBody
    public Object get(){
        return signService.selectAllTime();
    }


}
